<template>
  <div>
    <div>这是孙子</div>
    <div>{{ grandson }}</div>
    <button @click="btn">点击幸运大奖</button>
  </div>
</template>

<script>
export default {
  props: {
    grandson: {
      type: String,
      dedault: () => {},
    },
  },
  name: "grandson",
  mounted() {
    this.$emit("grandson");
  },
  methods: {
    rand(m, n) {
      return Math.ceil(Math.random() * (n - m + 1)) + m - 1;
    },
    btn() {
      const a = new Promise((resolve, reject) => {
        setTimeout(() => {
          let n = this.rand(1, 100);
          if (n <= 30) {
            resolve(n);
          } else {
            reject(n);
          }
        }, 1000);
      });
      a.then((res) => {
        alert("恭喜中奖"+res);
      }).catch((err) => {
        alert("再接再厉"+err);
      });
    },
  },
};
</script>
<style>
</style>